package com.whales.lms.rms.web.controller;

import java.util.List;

import javax.inject.Inject;

import org.jdom.Document;
import org.jdom.output.XMLOutputter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.whales.lms.rms.web.model.PcItemVO;
import com.whales.lms.rms.web.model.PcVO;
import com.whales.lms.rms.web.service.PcItemService;
import com.whales.lms.rms.web.service.PcService;
import com.whales.lms.rms.web.util.ConstantUtil;
import com.whales.shared.controller.GenericController;
import com.whales.shared.util.XmlUtil;

@Controller
@RequestMapping("/pc/*")
public class PcController extends GenericController<PcVO, PcVO, PcService> {
	@Inject
	private PcItemService pcItemService;
	
	@RequestMapping
	public @ResponseBody List<PcItemVO> findPcItemByType(PcItemVO pcItemVO) throws Exception{
		return pcItemService.findPcItemByType(pcItemVO);
	}
	
	@RequestMapping
	public @ResponseBody String updatePcTime(PcVO pcVO) throws Exception{
		Document doc;
		try{
			service.updateLifeTime(pcVO);
			doc = XmlUtil.buidDocForServerResponse(ConstantUtil.STATE_OKE);
		}catch(Exception e){
			e.printStackTrace();
			doc = XmlUtil.buidDocForServerResponse(ConstantUtil.STATE_ERR);
		}
		return new XMLOutputter().outputString(doc);
	}
}
